{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from zipline.pipeline import Pipeline\n",
    "from zipline.pipeline.data import USEquityPricing\n",
    "from sharadar.pipeline.factors import (\n",
    "    MarketCap,\n",
    "    EV,\n",
    "    Fundamentals\n",
    ")\n",
    "from sharadar.pipeline.engine import symbol, symbols, make_pipeline_engine\n",
    "from zipline.pipeline.filters import StaticAssets\n",
    "import time\n",
    "import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Equity(111630 [^VIX])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "symbol('^VIX')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Equity(118691 [SPY])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "symbol('SPY')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2020-07-22 13:49:34.916852] INFO: sharadar_db_bundle: Compute values for pipeline from 2020-02-03 to 2020-02-07.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2020-02-03 00:00:00+00:00</th>\n",
       "      <th>Equity(199059 [AAPL])</th>\n",
       "      <td>309.51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199623 [IBM])</th>\n",
       "      <td>143.73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199713 [F])</th>\n",
       "      <td>8.82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2020-02-04 00:00:00+00:00</th>\n",
       "      <th>Equity(199059 [AAPL])</th>\n",
       "      <td>308.66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199623 [IBM])</th>\n",
       "      <td>146.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199713 [F])</th>\n",
       "      <td>8.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2020-02-05 00:00:00+00:00</th>\n",
       "      <th>Equity(199059 [AAPL])</th>\n",
       "      <td>318.85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199623 [IBM])</th>\n",
       "      <td>149.11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199713 [F])</th>\n",
       "      <td>9.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2020-02-06 00:00:00+00:00</th>\n",
       "      <th>Equity(199059 [AAPL])</th>\n",
       "      <td>321.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199623 [IBM])</th>\n",
       "      <td>156.33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199713 [F])</th>\n",
       "      <td>8.31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2020-02-07 00:00:00+00:00</th>\n",
       "      <th>Equity(199059 [AAPL])</th>\n",
       "      <td>324.44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199623 [IBM])</th>\n",
       "      <td>153.52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199713 [F])</th>\n",
       "      <td>8.25</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                  Close\n",
       "2020-02-03 00:00:00+00:00 Equity(199059 [AAPL])  309.51\n",
       "                          Equity(199623 [IBM])   143.73\n",
       "                          Equity(199713 [F])       8.82\n",
       "2020-02-04 00:00:00+00:00 Equity(199059 [AAPL])  308.66\n",
       "                          Equity(199623 [IBM])   146.27\n",
       "                          Equity(199713 [F])       8.98\n",
       "2020-02-05 00:00:00+00:00 Equity(199059 [AAPL])  318.85\n",
       "                          Equity(199623 [IBM])   149.11\n",
       "                          Equity(199713 [F])       9.18\n",
       "2020-02-06 00:00:00+00:00 Equity(199059 [AAPL])  321.45\n",
       "                          Equity(199623 [IBM])   156.33\n",
       "                          Equity(199713 [F])       8.31\n",
       "2020-02-07 00:00:00+00:00 Equity(199059 [AAPL])  324.44\n",
       "                          Equity(199623 [IBM])   153.52\n",
       "                          Equity(199713 [F])       8.25"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "spe = make_pipeline_engine()\n",
    "\n",
    "pipe_start = pd.to_datetime('2020-02-03', utc=True)\n",
    "pipe_end = pd.to_datetime('2020-02-07', utc=True)\n",
    "\n",
    "\n",
    "pipe = Pipeline(columns={\n",
    "    'Close': USEquityPricing.close.latest,\n",
    "},\n",
    "screen = StaticAssets(symbols(['IBM', 'F', 'AAPL']))\n",
    ")\n",
    "\n",
    "stocks = spe.run_pipeline(pipe, pipe_start, pipe_end)\n",
    "stocks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2020-07-03 20:55:18.348540] INFO: sharadar_db_bundle: Compute pipeline values in chunks of 120 days.\n",
      "[2020-07-03 20:55:18.350274] INFO: sharadar_db_bundle: Compute values for pipeline from 2020-02-03 to 2020-02-07.\n",
      "[2020-07-03 20:55:18.356553] INFO: sharadar_db_bundle: Computing term 1 of 5 [AssetExists()]\n",
      "[2020-07-03 20:55:18.357422] INFO: sharadar_db_bundle: Term already in workspace: no computation needed\n",
      "[2020-07-03 20:55:18.358058] INFO: sharadar_db_bundle: Computing term 2 of 5 [Fundamentals{'field': 'sharesbas_arq'}]\n",
      "[2020-07-03 20:55:20.697451] INFO: sharadar_db_bundle: Elapsed time: 0:00:02.339389\n",
      "[2020-07-03 20:55:20.698366] INFO: sharadar_db_bundle: Computing term 3 of 5 [Fundamentals{'field': 'sharefactor_arq'}]\n",
      "[2020-07-03 20:55:21.922237] INFO: sharadar_db_bundle: Elapsed time: 0:00:01.223812\n",
      "[2020-07-03 20:55:21.923614] INFO: sharadar_db_bundle: Computing term 4 of 5 [USEquityPricing.close::float64]\n",
      "[2020-07-03 20:55:21.930245] INFO: sharadar_db_bundle: Elapsed time: 0:00:00.006607\n",
      "[2020-07-03 20:55:21.931656] INFO: sharadar_db_bundle: Computing term 5 of 5 [MarketCap([USEquityPricing.close, Fundamentals(...), Fundamentals(...)], 1)]\n",
      "[2020-07-03 20:55:21.937756] INFO: sharadar_db_bundle: Elapsed time: 0:00:00.006123\n",
      "CPU times: user 1.19 s, sys: 622 ms, total: 1.82 s\n",
      "Wall time: 3.69 s\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(48891, 1)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "pipe_mkt_cap = Pipeline(columns={\n",
    "    'mkt_cap': MarketCap()\n",
    "},\n",
    ")\n",
    "\n",
    "start_time = time.time()\n",
    "stocks = spe.run_pipeline(pipe_mkt_cap, pipe_start, pipe_end)\n",
    "stocks.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2020-07-03 20:55:28.480497] INFO: sharadar_db_bundle: Compute pipeline values in chunks of 120 days.\n",
      "[2020-07-03 20:55:28.482117] INFO: sharadar_db_bundle: Compute values for pipeline from 2020-02-03 to 2020-02-07.\n",
      "[2020-07-03 20:55:28.489209] INFO: sharadar_db_bundle: Computing term 1 of 9 [AssetExists()]\n",
      "[2020-07-03 20:55:28.490335] INFO: sharadar_db_bundle: Term already in workspace: no computation needed\n",
      "[2020-07-03 20:55:28.491284] INFO: sharadar_db_bundle: Computing term 2 of 9 [Fundamentals{'field': 'sharesbas_arq'}]\n",
      "[2020-07-03 20:55:28.496066] INFO: sharadar_db_bundle: Elapsed time: 0:00:00.004796\n",
      "[2020-07-03 20:55:28.496953] INFO: sharadar_db_bundle: Computing term 3 of 9 [Fundamentals{'field': 'sharefactor_arq'}]\n",
      "[2020-07-03 20:55:28.501872] INFO: sharadar_db_bundle: Elapsed time: 0:00:00.004916\n",
      "[2020-07-03 20:55:28.502813] INFO: sharadar_db_bundle: Computing term 4 of 9 [Fundamentals{'field': 'cashnequsd_arq'}]\n",
      "[2020-07-03 20:55:30.464896] INFO: sharadar_db_bundle: Elapsed time: 0:00:01.962110\n",
      "[2020-07-03 20:55:30.465883] INFO: sharadar_db_bundle: Computing term 5 of 9 [StaticAssets([], 0)]\n",
      "[2020-07-03 20:55:30.467465] INFO: sharadar_db_bundle: Elapsed time: 0:00:00.001590\n",
      "[2020-07-03 20:55:30.468191] INFO: sharadar_db_bundle: Computing term 6 of 9 [USEquityPricing.close::float64]\n",
      "[2020-07-03 20:55:30.473606] INFO: sharadar_db_bundle: Elapsed time: 0:00:00.005406\n",
      "[2020-07-03 20:55:30.474645] INFO: sharadar_db_bundle: Computing term 7 of 9 [Fundamentals{'field': 'debtusd_arq'}]\n",
      "[2020-07-03 20:55:31.757932] INFO: sharadar_db_bundle: Elapsed time: 0:00:01.283288\n",
      "[2020-07-03 20:55:31.759008] INFO: sharadar_db_bundle: Computing term 8 of 9 [MarketCap([USEquityPricing.close, Fundamentals(...), Fundamentals(...)], 1)]\n",
      "[2020-07-03 20:55:31.764592] INFO: sharadar_db_bundle: Elapsed time: 0:00:00.005588\n",
      "[2020-07-03 20:55:31.765848] INFO: sharadar_db_bundle: Computing term 9 of 9 [EV([MarketCap(...), Fundamentals(...), Fundamentals(...)], 1)]\n",
      "[2020-07-03 20:55:31.771568] INFO: sharadar_db_bundle: Elapsed time: 0:00:00.005740\n",
      "CPU times: user 1.15 s, sys: 534 ms, total: 1.69 s\n",
      "Wall time: 3.32 s\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>cash</th>\n",
       "      <th>debt</th>\n",
       "      <th>ev</th>\n",
       "      <th>mkt_cap</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2020-02-03 00:00:00+00:00</th>\n",
       "      <th>Equity(199059 [AAPL])</th>\n",
       "      <td>3.977100e+10</td>\n",
       "      <td>1.082920e+11</td>\n",
       "      <td>1.422776e+12</td>\n",
       "      <td>1.354255e+12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199623 [IBM])</th>\n",
       "      <td>1.022500e+10</td>\n",
       "      <td>7.149400e+10</td>\n",
       "      <td>1.885617e+11</td>\n",
       "      <td>1.272927e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199713 [F])</th>\n",
       "      <td>2.052300e+10</td>\n",
       "      <td>1.541110e+11</td>\n",
       "      <td>1.685584e+11</td>\n",
       "      <td>3.497039e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2020-02-04 00:00:00+00:00</th>\n",
       "      <th>Equity(199059 [AAPL])</th>\n",
       "      <td>3.977100e+10</td>\n",
       "      <td>1.082920e+11</td>\n",
       "      <td>1.419057e+12</td>\n",
       "      <td>1.350536e+12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199623 [IBM])</th>\n",
       "      <td>1.022500e+10</td>\n",
       "      <td>7.149400e+10</td>\n",
       "      <td>1.908112e+11</td>\n",
       "      <td>1.295422e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199713 [F])</th>\n",
       "      <td>2.052300e+10</td>\n",
       "      <td>1.541110e+11</td>\n",
       "      <td>1.691928e+11</td>\n",
       "      <td>3.560478e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2020-02-05 00:00:00+00:00</th>\n",
       "      <th>Equity(199059 [AAPL])</th>\n",
       "      <td>3.977100e+10</td>\n",
       "      <td>1.082920e+11</td>\n",
       "      <td>1.463643e+12</td>\n",
       "      <td>1.395122e+12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199623 [IBM])</th>\n",
       "      <td>1.022500e+10</td>\n",
       "      <td>7.149400e+10</td>\n",
       "      <td>1.933264e+11</td>\n",
       "      <td>1.320574e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199713 [F])</th>\n",
       "      <td>2.052300e+10</td>\n",
       "      <td>1.541110e+11</td>\n",
       "      <td>1.699858e+11</td>\n",
       "      <td>3.639775e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2020-02-06 00:00:00+00:00</th>\n",
       "      <th>Equity(199059 [AAPL])</th>\n",
       "      <td>3.977100e+10</td>\n",
       "      <td>1.082920e+11</td>\n",
       "      <td>1.475019e+12</td>\n",
       "      <td>1.406498e+12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199623 [IBM])</th>\n",
       "      <td>1.022500e+10</td>\n",
       "      <td>7.149400e+10</td>\n",
       "      <td>1.997207e+11</td>\n",
       "      <td>1.384517e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199713 [F])</th>\n",
       "      <td>1.750400e+10</td>\n",
       "      <td>1.553070e+11</td>\n",
       "      <td>1.709586e+11</td>\n",
       "      <td>3.315556e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2020-02-07 00:00:00+00:00</th>\n",
       "      <th>Equity(199059 [AAPL])</th>\n",
       "      <td>3.977100e+10</td>\n",
       "      <td>1.082920e+11</td>\n",
       "      <td>1.491471e+12</td>\n",
       "      <td>1.422950e+12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199623 [IBM])</th>\n",
       "      <td>1.022500e+10</td>\n",
       "      <td>7.149400e+10</td>\n",
       "      <td>1.986668e+11</td>\n",
       "      <td>1.373978e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199713 [F])</th>\n",
       "      <td>1.750400e+10</td>\n",
       "      <td>1.553070e+11</td>\n",
       "      <td>1.707192e+11</td>\n",
       "      <td>3.291617e+10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                         cash          debt  \\\n",
       "2020-02-03 00:00:00+00:00 Equity(199059 [AAPL])  3.977100e+10  1.082920e+11   \n",
       "                          Equity(199623 [IBM])   1.022500e+10  7.149400e+10   \n",
       "                          Equity(199713 [F])     2.052300e+10  1.541110e+11   \n",
       "2020-02-04 00:00:00+00:00 Equity(199059 [AAPL])  3.977100e+10  1.082920e+11   \n",
       "                          Equity(199623 [IBM])   1.022500e+10  7.149400e+10   \n",
       "                          Equity(199713 [F])     2.052300e+10  1.541110e+11   \n",
       "2020-02-05 00:00:00+00:00 Equity(199059 [AAPL])  3.977100e+10  1.082920e+11   \n",
       "                          Equity(199623 [IBM])   1.022500e+10  7.149400e+10   \n",
       "                          Equity(199713 [F])     2.052300e+10  1.541110e+11   \n",
       "2020-02-06 00:00:00+00:00 Equity(199059 [AAPL])  3.977100e+10  1.082920e+11   \n",
       "                          Equity(199623 [IBM])   1.022500e+10  7.149400e+10   \n",
       "                          Equity(199713 [F])     1.750400e+10  1.553070e+11   \n",
       "2020-02-07 00:00:00+00:00 Equity(199059 [AAPL])  3.977100e+10  1.082920e+11   \n",
       "                          Equity(199623 [IBM])   1.022500e+10  7.149400e+10   \n",
       "                          Equity(199713 [F])     1.750400e+10  1.553070e+11   \n",
       "\n",
       "                                                           ev       mkt_cap  \n",
       "2020-02-03 00:00:00+00:00 Equity(199059 [AAPL])  1.422776e+12  1.354255e+12  \n",
       "                          Equity(199623 [IBM])   1.885617e+11  1.272927e+11  \n",
       "                          Equity(199713 [F])     1.685584e+11  3.497039e+10  \n",
       "2020-02-04 00:00:00+00:00 Equity(199059 [AAPL])  1.419057e+12  1.350536e+12  \n",
       "                          Equity(199623 [IBM])   1.908112e+11  1.295422e+11  \n",
       "                          Equity(199713 [F])     1.691928e+11  3.560478e+10  \n",
       "2020-02-05 00:00:00+00:00 Equity(199059 [AAPL])  1.463643e+12  1.395122e+12  \n",
       "                          Equity(199623 [IBM])   1.933264e+11  1.320574e+11  \n",
       "                          Equity(199713 [F])     1.699858e+11  3.639775e+10  \n",
       "2020-02-06 00:00:00+00:00 Equity(199059 [AAPL])  1.475019e+12  1.406498e+12  \n",
       "                          Equity(199623 [IBM])   1.997207e+11  1.384517e+11  \n",
       "                          Equity(199713 [F])     1.709586e+11  3.315556e+10  \n",
       "2020-02-07 00:00:00+00:00 Equity(199059 [AAPL])  1.491471e+12  1.422950e+12  \n",
       "                          Equity(199623 [IBM])   1.986668e+11  1.373978e+11  \n",
       "                          Equity(199713 [F])     1.707192e+11  3.291617e+10  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "pipe_mkt_cap_ev = Pipeline(columns={\n",
    "    'mkt_cap': MarketCap(),\n",
    "    'ev': EV(),\n",
    "    'debt': Fundamentals(field='debtusd_arq'),\n",
    "    'cash': Fundamentals(field='cashnequsd_arq')\n",
    "},\n",
    "screen = StaticAssets(symbols(['IBM', 'F', 'AAPL']))\n",
    ")\n",
    "\n",
    "stocks = spe.run_pipeline(pipe_mkt_cap_ev, pipe_start, pipe_end)\n",
    "stocks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2020-07-22 13:49:47.051972] INFO: sharadar_db_bundle: Compute values for pipeline from 2020-02-03 to 2020-02-07.\n",
      "CPU times: user 1.72 s, sys: 752 ms, total: 2.47 s\n",
      "Wall time: 3.54 s\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>cash</th>\n",
       "      <th>debt</th>\n",
       "      <th>ev</th>\n",
       "      <th>mkt_cap</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2020-02-03 00:00:00+00:00</th>\n",
       "      <th>Equity(199059 [AAPL])</th>\n",
       "      <td>3.977100e+10</td>\n",
       "      <td>1.082920e+11</td>\n",
       "      <td>1.422776e+12</td>\n",
       "      <td>1.354255e+12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199623 [IBM])</th>\n",
       "      <td>1.022500e+10</td>\n",
       "      <td>7.149400e+10</td>\n",
       "      <td>1.885617e+11</td>\n",
       "      <td>1.272927e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199713 [F])</th>\n",
       "      <td>2.052300e+10</td>\n",
       "      <td>1.541110e+11</td>\n",
       "      <td>1.685584e+11</td>\n",
       "      <td>3.497039e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2020-02-04 00:00:00+00:00</th>\n",
       "      <th>Equity(199059 [AAPL])</th>\n",
       "      <td>3.977100e+10</td>\n",
       "      <td>1.082920e+11</td>\n",
       "      <td>1.419057e+12</td>\n",
       "      <td>1.350536e+12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199623 [IBM])</th>\n",
       "      <td>1.022500e+10</td>\n",
       "      <td>7.149400e+10</td>\n",
       "      <td>1.908112e+11</td>\n",
       "      <td>1.295422e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199713 [F])</th>\n",
       "      <td>2.052300e+10</td>\n",
       "      <td>1.541110e+11</td>\n",
       "      <td>1.691928e+11</td>\n",
       "      <td>3.560478e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2020-02-05 00:00:00+00:00</th>\n",
       "      <th>Equity(199059 [AAPL])</th>\n",
       "      <td>3.977100e+10</td>\n",
       "      <td>1.082920e+11</td>\n",
       "      <td>1.463643e+12</td>\n",
       "      <td>1.395122e+12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199623 [IBM])</th>\n",
       "      <td>1.022500e+10</td>\n",
       "      <td>7.149400e+10</td>\n",
       "      <td>1.933264e+11</td>\n",
       "      <td>1.320574e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199713 [F])</th>\n",
       "      <td>2.052300e+10</td>\n",
       "      <td>1.541110e+11</td>\n",
       "      <td>1.699858e+11</td>\n",
       "      <td>3.639775e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2020-02-06 00:00:00+00:00</th>\n",
       "      <th>Equity(199059 [AAPL])</th>\n",
       "      <td>3.977100e+10</td>\n",
       "      <td>1.082920e+11</td>\n",
       "      <td>1.475019e+12</td>\n",
       "      <td>1.406498e+12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199623 [IBM])</th>\n",
       "      <td>1.022500e+10</td>\n",
       "      <td>7.149400e+10</td>\n",
       "      <td>1.997207e+11</td>\n",
       "      <td>1.384517e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199713 [F])</th>\n",
       "      <td>1.750400e+10</td>\n",
       "      <td>1.553070e+11</td>\n",
       "      <td>1.709586e+11</td>\n",
       "      <td>3.315556e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2020-02-07 00:00:00+00:00</th>\n",
       "      <th>Equity(199059 [AAPL])</th>\n",
       "      <td>3.977100e+10</td>\n",
       "      <td>1.082920e+11</td>\n",
       "      <td>1.488102e+12</td>\n",
       "      <td>1.419581e+12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199623 [IBM])</th>\n",
       "      <td>1.022500e+10</td>\n",
       "      <td>7.149400e+10</td>\n",
       "      <td>1.972321e+11</td>\n",
       "      <td>1.359631e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199713 [F])</th>\n",
       "      <td>1.750400e+10</td>\n",
       "      <td>1.553070e+11</td>\n",
       "      <td>1.707192e+11</td>\n",
       "      <td>3.291617e+10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                         cash          debt  \\\n",
       "2020-02-03 00:00:00+00:00 Equity(199059 [AAPL])  3.977100e+10  1.082920e+11   \n",
       "                          Equity(199623 [IBM])   1.022500e+10  7.149400e+10   \n",
       "                          Equity(199713 [F])     2.052300e+10  1.541110e+11   \n",
       "2020-02-04 00:00:00+00:00 Equity(199059 [AAPL])  3.977100e+10  1.082920e+11   \n",
       "                          Equity(199623 [IBM])   1.022500e+10  7.149400e+10   \n",
       "                          Equity(199713 [F])     2.052300e+10  1.541110e+11   \n",
       "2020-02-05 00:00:00+00:00 Equity(199059 [AAPL])  3.977100e+10  1.082920e+11   \n",
       "                          Equity(199623 [IBM])   1.022500e+10  7.149400e+10   \n",
       "                          Equity(199713 [F])     2.052300e+10  1.541110e+11   \n",
       "2020-02-06 00:00:00+00:00 Equity(199059 [AAPL])  3.977100e+10  1.082920e+11   \n",
       "                          Equity(199623 [IBM])   1.022500e+10  7.149400e+10   \n",
       "                          Equity(199713 [F])     1.750400e+10  1.553070e+11   \n",
       "2020-02-07 00:00:00+00:00 Equity(199059 [AAPL])  3.977100e+10  1.082920e+11   \n",
       "                          Equity(199623 [IBM])   1.022500e+10  7.149400e+10   \n",
       "                          Equity(199713 [F])     1.750400e+10  1.553070e+11   \n",
       "\n",
       "                                                           ev       mkt_cap  \n",
       "2020-02-03 00:00:00+00:00 Equity(199059 [AAPL])  1.422776e+12  1.354255e+12  \n",
       "                          Equity(199623 [IBM])   1.885617e+11  1.272927e+11  \n",
       "                          Equity(199713 [F])     1.685584e+11  3.497039e+10  \n",
       "2020-02-04 00:00:00+00:00 Equity(199059 [AAPL])  1.419057e+12  1.350536e+12  \n",
       "                          Equity(199623 [IBM])   1.908112e+11  1.295422e+11  \n",
       "                          Equity(199713 [F])     1.691928e+11  3.560478e+10  \n",
       "2020-02-05 00:00:00+00:00 Equity(199059 [AAPL])  1.463643e+12  1.395122e+12  \n",
       "                          Equity(199623 [IBM])   1.933264e+11  1.320574e+11  \n",
       "                          Equity(199713 [F])     1.699858e+11  3.639775e+10  \n",
       "2020-02-06 00:00:00+00:00 Equity(199059 [AAPL])  1.475019e+12  1.406498e+12  \n",
       "                          Equity(199623 [IBM])   1.997207e+11  1.384517e+11  \n",
       "                          Equity(199713 [F])     1.709586e+11  3.315556e+10  \n",
       "2020-02-07 00:00:00+00:00 Equity(199059 [AAPL])  1.488102e+12  1.419581e+12  \n",
       "                          Equity(199623 [IBM])   1.972321e+11  1.359631e+11  \n",
       "                          Equity(199713 [F])     1.707192e+11  3.291617e+10  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "pipe = Pipeline(columns={\n",
    "    'mkt_cap': MarketCap(),\n",
    "    'ev': EV(),\n",
    "    'debt': Fundamentals(field='debtusd_arq'),\n",
    "    'cash': Fundamentals(field='cashnequsd_arq')\n",
    "},\n",
    "screen = StaticAssets(symbols(['IBM', 'F', 'AAPL']))\n",
    ")\n",
    "\n",
    "stocks = spe.run_pipeline(pipe, pipe_start, pipe_end)\n",
    "stocks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2020-07-22 13:50:05.540844] INFO: sharadar_db_bundle: Compute values for pipeline from 2020-02-03 to 2020-02-03.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>cash</th>\n",
       "      <th>debt</th>\n",
       "      <th>ev</th>\n",
       "      <th>mkt_cap</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2020-02-03 00:00:00+00:00</th>\n",
       "      <th>Equity(199059 [AAPL])</th>\n",
       "      <td>3.977100e+10</td>\n",
       "      <td>1.082920e+11</td>\n",
       "      <td>1.422776e+12</td>\n",
       "      <td>1.354255e+12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199623 [IBM])</th>\n",
       "      <td>1.022500e+10</td>\n",
       "      <td>7.149400e+10</td>\n",
       "      <td>1.885617e+11</td>\n",
       "      <td>1.272927e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Equity(199713 [F])</th>\n",
       "      <td>2.052300e+10</td>\n",
       "      <td>1.541110e+11</td>\n",
       "      <td>1.685584e+11</td>\n",
       "      <td>3.497039e+10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                         cash          debt  \\\n",
       "2020-02-03 00:00:00+00:00 Equity(199059 [AAPL])  3.977100e+10  1.082920e+11   \n",
       "                          Equity(199623 [IBM])   1.022500e+10  7.149400e+10   \n",
       "                          Equity(199713 [F])     2.052300e+10  1.541110e+11   \n",
       "\n",
       "                                                           ev       mkt_cap  \n",
       "2020-02-03 00:00:00+00:00 Equity(199059 [AAPL])  1.422776e+12  1.354255e+12  \n",
       "                          Equity(199623 [IBM])   1.885617e+11  1.272927e+11  \n",
       "                          Equity(199713 [F])     1.685584e+11  3.497039e+10  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stocks = spe.run_pipeline(pipe, pipe_start)\n",
    "stocks"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
